package com.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bean.District;
import com.bean.House;
import com.bean.HouseType;
import com.bean.SearchCondition;
import com.bean.Street;
import com.bean.Type;
import com.biz.DistrictBiz;
import com.biz.HouseBiz;
import com.biz.HouseTypeBiz;
import com.biz.impl.DistrictBizImpl;
import com.biz.impl.HouseBizImpl;
import com.biz.impl.HouseTypeBizImpl;
import com.dao.HouseDao;
import com.dao.TypeDao;
import com.dao.impl.HouseDaoImpl;
import com.dao.impl.TypeDaoImpl;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class SearchAction extends ActionSupport {
	private List<District> districts;
	private List<Street> streets;
	private List<HouseType> houseTypes;
	private List<Type> types;
	private List<House> houses;
	private String search = "0-0-0-0-0-0";
	private SearchCondition sc;
	//分页查询
	private int pageIndex = 1;
	private int totalPages;
	
	@Override
	public String execute() {
		DistrictBiz districtBiz = new DistrictBizImpl();
		districts = districtBiz.getAll();// 所有区域
		HouseTypeBiz houseTypeBiz = new HouseTypeBizImpl();
		houseTypes = houseTypeBiz.getAll();// 所有房型
		TypeDao typeDao = new TypeDaoImpl();
		types = typeDao.getAll();// 所有类型
		
		sc = new SearchCondition();// 搜索条件
		String[] flags = search.split("-");
		sc.setDistrictId(Integer.parseInt(flags[0]));
		sc.setStreetId(Integer.parseInt(flags[1]));
		sc.setFromPrice(Integer.parseInt(flags[2]));
		sc.setToPrice(Integer.parseInt(flags[3]));
		sc.setHouseTypeId(Integer.parseInt(flags[4]));
		sc.setTypeId(Integer.parseInt(flags[5]));
		
		HouseBiz houseBiz = new HouseBizImpl();
		int totalRec = houseBiz.getTotal(sc);
		totalPages = totalRec % 10 > 0 ? totalRec / 10 + 1 : totalRec / 10;
		houses = houseBiz.search(sc, pageIndex);// 根据搜索条件搜索
		
		return SUCCESS;
	}

	public List<House> getHouses() {
		return houses;
	}

	public void setHouses(List<House> houses) {
		this.houses = houses;
	}

	public List<District> getDistricts() {
		return districts;
	}

	public void setDistricts(List<District> districts) {
		this.districts = districts;
	}

	public List<Street> getStreets() {
		return streets;
	}

	public void setStreets(List<Street> streets) {
		this.streets = streets;
	}

	public List<HouseType> getHouseTypes() {
		return houseTypes;
	}

	public void setHouseTypes(List<HouseType> houseTypes) {
		this.houseTypes = houseTypes;
	}

	public List<Type> getTypes() {
		return types;
	}

	public void setTypes(List<Type> types) {
		this.types = types;
	}

	public String getSearch() {
		return search;
	}

	public void setSearch(String search) {
		this.search = search;
	}

	public SearchCondition getSc() {
		return sc;
	}

	public void setSc(SearchCondition sc) {
		this.sc = sc;
	}

	public int getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	public int getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}

}
